package com.changxu.wc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


import java.io.IOException;

public class WordCountDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf,"WordCountDriver");
//       指定jar的本地路径
        job.setJarByClass(WordCountDriver.class);

//        指定Mapper和Reducer类
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

//        指定Mapper的输出kv类型
        job.setMapOutputKeyClass(WordCountBean.class);
        job.setMapOutputValueClass(NullWritable.class);

//        指定最终输出kv类型
        job.setOutputKeyClass(WordCountBean.class);
        job.setOutputValueClass(NullWritable.class);

//       指定reducerTask数量
        job.setNumReduceTasks(1);

//        执行输入输出参数
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

//        提交作业
        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
